// font-303133-12 同时允许 font-12-303133
// font-303133-20 同时允许 font-20-303133
// 批量生成css 行高自动生成

// 常用的样式需要给全局定义font-text == font-12-303133
class Font {
  constructor(params) {
    this.color = params.color || "#303133";
    this.size = params.size || "18";
    this.alias = params.alias || "";
  }
  getConvert() {
    return {
      color: this.color,
      size: this.size,
      lineHeight: this.getLineHeight(),
      pureColor: this.color.indexOf("#") == 0 ? this.color.substring(1) : "",
      alias: this.alias
    };
  }
  getLineHeight() {
    let size = parseInt(this.size) || 12;
    if (size == 12) {
      return 18;
    } else if (size == 14) {
      return 20;
    } else if (size == 16) {
      return 22;
    } else if (size == 18) {
      return 26;
    } else if (size == 20) {
      return 28;
    }
    return 18;
  }
}
let Fonts = [
  new Font({
    color: "#303133",
    size: "20"
  }),
  new Font({
    color: "#303133",
    size: "18"
  }),
  new Font({
    color: "#ffffff",
    size: "16"
  }),
  new Font({
    color: "#303133",
    size: "16"
  }),
  new Font({
    color: "#303133",
    size: "14"
  }),
  new Font({
    color: "#606266",
    size: "12"
  }),
  new Font({
    color: "#909399",
    size: "12"
  }),
  new Font({
    color: "#90939966",
    size: "12"
  }),
  new Font({
    color: "#3258de",
    size: "12"
  }),
  new Font({
    color: "#52c4a1",
    size: "12"
  }),
  new Font({
    color: "#ff8e0d",
    size: "12"
  }),
  new Font({
    color: "#ff4d4f",
    size: "12"
  })
];

exports.getVariable = () => {
  return Fonts.map(item => {
    let { color, size, lineHeight, pureColor, alias } = item.getConvert();
    let str = ``;
    if (pureColor) {
      str += `
.font-${pureColor}-${size} {
  color:${color} ;
  font-size: ${size}px;
  line-height: ${lineHeight}px;
}
.font-${size}-${pureColor} {
  color:${color} ;
  font-size: ${size}px;
  line-height: ${lineHeight}px;
}`;
    }
    if (alias) {
      str += `
.font-${alias} {
  color:${color} ;
  font-size: ${size}px;
  line-height: ${lineHeight}px;
}`;
    }
    return str;
  }).reduce((pre, cur) => {
    pre += cur;
    return pre;
  }, "");
};
